package com.cn.kabalifeuser.config;

import android.app.Activity;
import android.graphics.Bitmap;
import android.widget.Toast;


import com.cn.kabalifeuser.base.MyApplication;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMMin;
import com.umeng.socialize.media.UMWeb;

import java.io.File;

/**
 * Created by 晓林 on 2020/8/25.
 * function:
 */
public class ShareUtil {

    public static Activity activity;
    public static UMShareListener shareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(MyApplication.getContext(), "分享成功", Toast.LENGTH_LONG).show();
//            mPresenter.getShareMoney(LoginHelper.getUserInfo().getUid(), LoginHelper.getUserInfo().getUtoken());
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(MyApplication.getContext(), "分享失败咯", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(MyApplication.getContext(), "分享取消咯", Toast.LENGTH_LONG).show();

        }
    };

    //TODO  微信

    /**
     * 微信分享  图 单个
     *
     * @param context
     * @param imgUrl  图片链接
     */
    public static void shareWXImage(Activity context, String imgUrl) {
        UMImage image = new UMImage(context, imgUrl);
        image.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(image)
                .setPlatform(SHARE_MEDIA.WEIXIN)
                .setCallback(shareListener).share();
    }

    /**
     * 微信分享  图 单个
     *
     * @param context
     * @param imgUrl  图片链接
     */
    public static void shareWXImage(Activity context, Bitmap imgUrl) {
        UMImage image = new UMImage(context, imgUrl);
        image.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(image)
                .setPlatform(SHARE_MEDIA.WEIXIN)
                .setCallback(shareListener).share();
    }

    /**
     * 微信朋友圈分享
     *
     * @param context
     * @param imgUrl  图片链接
     */
    public static void shareWXImageMany(Activity context, String imgUrl) {
        UMImage imageurl = new UMImage(context, imgUrl);
        imageurl.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(imageurl)
                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE.toSnsPlatform().mPlatform)
                .setCallback(shareListener).share();


    }

    /**
     * 微信朋友圈分享
     *
     * @param context
     * @param imgUrl  File
     */
    public static void shareWXImageMany(Activity context, File imgUrl) {
        UMImage imageurl = new UMImage(context, imgUrl);
        imageurl.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(imageurl)
                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE.toSnsPlatform().mPlatform)
                .setCallback(shareListener).share();


    }

    /**
     * 微信朋友圈分享
     * bitmap
     *
     * @param context
     * @param imgUrl  图片链接
     */
    public static void shareWXImageMany(Activity context, Bitmap imgUrl) {
        UMImage imageurl = new UMImage(context, imgUrl);
        imageurl.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(imageurl)
                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE.toSnsPlatform().mPlatform)
                .setCallback(shareListener).share();


    }

    //TODO  qq

    /**
     * QQ分享  单个
     *
     * @param context
     * @param imgUrl  图片 链接
     */
    public static void shareQQImage(Activity context, String imgUrl) {
        UMImage image = new UMImage(context, imgUrl);
        image.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(image)
                .setPlatform(SHARE_MEDIA.QQ)
                .setCallback(shareListener).share();
    }

    /**
     * QQ分享  单个
     *
     * @param context
     * @param imgUrl  图片 链接
     */
    public static void shareQQImage(Activity context, Bitmap imgUrl) {
        UMImage image = new UMImage(context, imgUrl);
        image.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(image)
                .setPlatform(SHARE_MEDIA.QQ)
                .setCallback(shareListener).share();
    }
    //TODO  微博

    /**
     * 微博 分享 单个
     *
     * @param context
     * @param imgUrl  图片 链接
     */
    public static void shareWBImage(Activity context, String imgUrl) {
        UMImage image = new UMImage(context, imgUrl);
        image.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(image)
                .setPlatform(SHARE_MEDIA.SINA)
                .setCallback(shareListener).share();
    }

    /**
     * 微博 分享 单个
     *
     * @param context
     * @param imgUrl  图片 链接
     */
    public static void shareWBImage(Activity context, Bitmap imgUrl) {
        UMImage image = new UMImage(context, imgUrl);
        image.setThumb(new UMImage(context, imgUrl));
        new ShareAction(context).withMedia(image)
                .setPlatform(SHARE_MEDIA.SINA)
                .setCallback(shareListener).share();
    }

    /**
     * 微信。分享鏈接
     *
     * @param context
     * @param umWeb
     */
    public static void shareWXUrl(Activity context, UMWeb umWeb) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.WEIXIN.toSnsPlatform().mPlatform)
                .withMedia(umWeb)
                .setCallback(shareListener).share();
    }

    /**
     * 微信朋友圈。分享鏈接
     *
     * @param context
     * @param umWeb
     */
    public static void shareWXManyUrl(Activity context, UMWeb umWeb) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE.toSnsPlatform().mPlatform)
                .withMedia(umWeb)
                .setCallback(shareListener).share();
    }

    /**
     * QQ。分享鏈接
     *
     * @param context
     * @param umWeb
     */
    public static void shareQQUrl(Activity context, UMWeb umWeb) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.QQ)
                .withMedia(umWeb)
                .setCallback(shareListener).share();
    }

    /**
     * QQ。分享鏈接
     *
     * @param context
     * @param umWeb
     */
    public static void shareQQZONEUrl(Activity context, UMWeb umWeb) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.QZONE)
                .withMedia(umWeb)
                .setCallback(shareListener).share();
    }

    /**
     * 微博。分享鏈接
     *
     * @param context
     * @param umWeb
     */
    public static void shareWBUrl(Activity context, UMWeb umWeb) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.SINA)
                .withMedia(umWeb)
                .setCallback(shareListener).share();
    }

    /**
     * 微信。分享文本
     *
     * @param context
     * @param str
     */
    public static void shareWXText(Activity context, String str) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.WEIXIN.toSnsPlatform().mPlatform)
                .withText(str)
                .setCallback(shareListener).share();
    }

    /**
     * 微信朋友圈。分享文本
     *
     * @param context
     * @param str
     */
    public static void shareWXManyText(Activity context, String str) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE.toSnsPlatform().mPlatform)
                .withText(str)
                .setCallback(shareListener).share();
    }

    /**
     * QQ。分享本
     *
     * @param context
     * @param str
     */
    public static void shareQQText(Activity context, String str) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.QQ)
                .withText(str)
                .setCallback(shareListener).share();
    }

    /**
     * QQ。分享文本
     *
     * @param context
     * @param str
     */
    public static void shareQQZONEText(Activity context, String str) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.QZONE)
                .withText(str)
                .setCallback(shareListener).share();
    }

    /**
     * 微博。分享文本
     *
     * @param context
     * @param str
     */
    public static void shareWBText(Activity context, String str) {
        activity = context;
        new ShareAction(context)
                .setPlatform(SHARE_MEDIA.SINA)
                .withText(str)
                .setCallback(shareListener).share();
    }


    /**
     * 小程序分享
     *
     * @param context this
     * @param image   小程序的封面图
     * @param title   小程序标题
     * @param path    小程序的路径
     *                umMin.setUserName("gh_5932eada0023");
     *                这个是小程序原始id。
     */
    public static void shareSmall(Activity context, String image, String title, String path) {
        activity = context;
        UMMin umMin = new UMMin("http://mobile.umeng.com/social");
        umMin.setThumb(new UMImage(context, image));
        umMin.setTitle(title);
        umMin.setDescription(title);
        umMin.setPath(path);
        umMin.setUserName("gh_409f1c7f2d74");
        com.umeng.socialize.Config.setMiniPreView();
        new ShareAction(context)
                .withMedia(umMin)
                .setPlatform(SHARE_MEDIA.WEIXIN)
                .setCallback(shareListener).share();

    }
}
